import extnames from '../dependencies/extnames.mjs';
import dirs from '../dependencies/dirs.mjs';
import path from 'path';
import fs from 'fs';
import readdirSync from '../utils/files/readdirSync.mjs';

export default function (args, config) {
    const dir = path.join(dirs.run_project, 'src', 'html');

    if (!config.devServer) { config.devServer = {}; }

    config.devServer.hot = true;

    {
        config.devServer.open = [];
        if (!fs.existsSync(dir)) { return; }

        readdirSync(dir).forEach(filePath => {
            const extname = path.extname(filePath);
            const filename = path.basename(filePath);
            if (extnames.html.includes(extname)) {
                config.devServer.open.push(path.join('html', filename).replaceAll('\\', '/'));
            }
        });
    }
};
